<?php
require_once APPLICATION_PATH . '/../library/eub/eub.class.php';
require_once APPLICATION_PATH . '/../library/eub/xmlParse.class.php';
class Uuch_eub {
    public static function createdEub($id,$province,$city)
    {
        $billItem = Application_Model_wayBillItem::load($id);
        $productWeight = $billItem->getWeightByType(Application_Model_WeightType::ProductWeight);
        $bagWeight = $billItem->getWeightByType(Application_Model_WeightType::BagWeight);
        $weight = $billItem->getWeightByType(Application_Model_WeightType::FirstWeight);
        $forecastWeight = $weight?$weight:($productWeight+$bagWeight);
        $reportFee = $billItem->getFeeByType(Application_Model_FeeType::ReprotValue);
        $content = '<?xml version="1.0" encoding="UTF-8"?>';
        $content .= '<orders xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">';
        $content .= '<order>';
        $content .= '<orderid>'.$billItem->BillNo.'</orderid>';
        $content .= '<customercode>Taomore</customercode>';
        $content .= '<vipcode>00000000000001</vipcode>';
        $content .= '<clcttype>1</clcttype>';
        $content .= '<pod>false</pod>';
        $content .= '<untread>Abandoned</untread>';
        $content .= '<volweight>123</volweight>';
        $content .= '<startdate>'.date("Y-m-d").'T18:30:00</startdate>';
        $content .= '<enddate>'.date("Y-m-d").'T22:30:00</enddate>';
        $content .= '<printcode>00</printcode>';
        $content .= '<sender>';
        $content .= '<name>You Qi</name>';
        $content .= '<postcode>518049</postcode>';
        $content .= '<phone>0755-88605979</phone>';
        $content .= '<mobile>13243877686</mobile>';
        $content .= '<country>CN</country>';
        $content .= '<province>441402</province>';
        $content .= '<city>441402</city>';
        $content .= '<county>441402</county>';
        $content .= '<company>UUCH</company>';
        $content .= '<street>Building 2 YouQi warehouse ShanCheng logistics park Tangtou  avenue  Shiyan street Baoan District</street>';
        $content .= '<email>service@uuch.com</email>';
        $content .= '</sender>';
        $content .= '<receiver>';
        $content .= '<name>'.$billItem->Consignee.'</name>';
        $content .= '<postcode>'.$billItem->ConPostCode.'</postcode>';
        $content .= '<phone>'.$billItem->ConTel.'</phone>';
        $content .= '<mobile>'.$billItem->ConTel.'</mobile>';
        $content .= '<country>'.$billItem->CityBy->Word.'</country>';
        $content .= '<province>'.$province.'</province>';
        $content .= '<city>'.$city.'</city>';
        $content .= '<street>'.$billItem->ConAdd.'</street>';
        $content .= '</receiver>';
        $content .= '<collect>';
        $content .= '<name>SZICE</name>';
        $content .= '<postcode>518049</postcode>';
        $content .= '<phone>0755-88605979</phone>';
        $content .= '<mobile>13243877686</mobile>';
        $content .= '<country>CN</country>';
        $content .= '<province>441402</province>';
        $content .= '<city>441402</city>';
        $content .= '<county>441402</county>';
        $content .= '<company/>';
        $content .= '<street>Building 2 YouQi warehouse ShanCheng logistics park Tangtou  avenue  Shiyan street Baoan District</street>';
        $content .= '<email>service@uuch.com</email>';
        $content .= '</collect>';
        $content .= '<items>';
        $content .= '<item>';
        $content .= '<cnname>礼物</cnname>';
        $content .= '<enname>Gift</enname>';
        $content .= '<count>1</count>';
        $content .= '<weight>'.number_format($forecastWeight/1000,3).'</weight>';
        $content .= '<delcarevalue>'.($reportFee>0? number_format($reportFee,3,'.',''):"20.000").'</delcarevalue>';
        $content .= '<origin>CN</origin>';
        $content .= '<description>Gift</description>';
        $content .= '</item>';
        $content .= '</items>';
        $content .= '</order>';
        $content .= '</orders>';
        $resultxml = new Eub(Eub::SHIP_ORDER, Eub::METHOD_POST, $content);
        $response = $resultxml->_http($resultxml->getMethod());
		//file_put_contents('test_log.txt', $response . "\n\r", FILE_APPEND);
		file_put_contents('../data/eub_'. date('Y-m-d') . '.txt', $response . "\r\n", FILE_APPEND);
        $xml = new xmlParse($response);
        $result = $xml->loadBillid();
        //var_dump($result);
        return $result;
    }
    
    public static function selbill($billNo)
    {
        $resultxml = new Eub(Eub::DELETE_MAILNUM_URL.$billNo, Eub::METHOD_GET);
        $response = $resultxml->_http($resultxml->getMethod());

        $xml = new xmlParse($response);
        var_dump($xml);
        exit;
    }
}